﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Xyz.BusinessObjects;
using Xyz.DataObjects.Interfaces;

namespace Xyz.DataObjects.Entity.Dao
{
    public class EntityAircraftSeatDao : IAircraftSeatDao
    {
        public List<AircraftSeat> GetAllAircraftSeats(int aircraftId)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var aircraftSeats = new List<AircraftSeat>();
                var query = context.AircraftSeatEntities.Where(x => x.AircraftId == aircraftId && x.SeatTypeCode != "LV" && x.SeatTypeCode != "EM").AsQueryable().ToList();

                query.ForEach(x => aircraftSeats.Add(Mapper.Map(x)));

                return aircraftSeats;

            }
        }
        public List<AircraftSeat> GetAircraftSeatsPlan(int aircraftId)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var aircraftSeats = new List<AircraftSeat>();
                var query = context.AircraftSeatEntities.Where(x => x.AircraftId == aircraftId).AsQueryable().ToList();

                query.ForEach(x => aircraftSeats.Add(Mapper.Map(x)));

                return aircraftSeats;

            }
        }

        public AircraftSeat GetAircraftSeatByAircraftIdSeatCode(int aircraftId, string seatCode)
         {
             using (var context = EntityObjectFactory.CreateContext())
             {
                 var aircraftSeat = context.AircraftSeatEntities.SingleOrDefault(x => x.AircraftId == aircraftId && x.SeatNo == seatCode);

                 if (aircraftSeat == null)
                 {
                     return null;
                 }
                 return Mapper.Map(aircraftSeat);
             }
         }

        public List<AircraftSeat> GetAircraftSeatByAircraftIdSeatTypeCode(int aircraftId, string seatTypeCode)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var aircraftSeats = new List<AircraftSeat>();
                var query = context.AircraftSeatEntities.Where(x => x.AircraftId == aircraftId && x.SeatTypeCode == seatTypeCode).AsQueryable().ToList();

                query.ForEach(x => aircraftSeats.Add(Mapper.Map(x)));

                return aircraftSeats;
            }
        }

        public AircraftSeat GetAircraftSeatByAircraftSeatId(int aircrafSeattId)
        {
            using (var context = EntityObjectFactory.CreateContext())
            {
                var aircraftSeat = context.AircraftSeatEntities.SingleOrDefault(x => x.AircraftSeatId == aircrafSeattId);

                return Mapper.Map(aircraftSeat);
            }
        }
    }
}
